package com.sis.db;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sis.constant.MergeFileConstants;

public class DataSource extends DataBaseService{
	
	
	public List<Map<String,String>> findUser() throws Exception {
		
		List<Map<String,String>> listMap = new ArrayList<>();
		try{
			ResultSet rs =  executeBateRS(MergeFileConstants.FINDUDER,null);
			while(rs.next()){
				Map<String, String> map = new HashMap<String, String>();
				map.put(MergeFileConstants.USERCODE, rs.getString(MergeFileConstants.USERCODE));
				map.put(MergeFileConstants.USERNAME, rs.getString(MergeFileConstants.USERNAME));
				listMap.add(map);
			}
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
		
		return listMap;
	}
	
	
	public Map<String,Map<String,String>> findCustomerEntity(String userName) throws Exception{
		
		Map<String,Map<String,String>> result = new HashMap<>();
		
		try{
			List<String> listArg = new ArrayList<>();
			listArg.add(userName);
			ResultSet rs =  executeBateRS(MergeFileConstants.FINDPRODUCTENTITYALLCOLUMN,listArg);
			while(rs.next()){
				Map<String,String> map = new HashMap<>();
				
				map.put(MergeFileConstants.NAME , rs.getString(MergeFileConstants.NAME));
				map.put(MergeFileConstants.SKU , rs.getString(MergeFileConstants.SKU));
				map.put(MergeFileConstants.CUSTOMER_MATERIAL_INFO_APPLY , rs.getString(MergeFileConstants.CUSTOMER_MATERIAL_INFO_APPLY));
				map.put(MergeFileConstants.SHORT_DESCRIPTION  , rs.getString(MergeFileConstants.SHORT_DESCRIPTION));
				map.put(MergeFileConstants.DESCRIPTION  , rs.getString(MergeFileConstants.DESCRIPTION));
				map.put(MergeFileConstants.TYPE_ID  , rs.getString(MergeFileConstants.TYPE_ID));
				map.put(MergeFileConstants.WEIGHT  , rs.getString(MergeFileConstants.WEIGHT));
				map.put(MergeFileConstants.STATUS , "2");
				map.put(MergeFileConstants.TAX_CLASS_ID  , rs.getString(MergeFileConstants.TAX_CLASS_ID));
				map.put(MergeFileConstants.URL_KEY  , rs.getString(MergeFileConstants.URL_KEY));
				map.put(MergeFileConstants.URL_PATH  , rs.getString(MergeFileConstants.URL_PATH));
				map.put(MergeFileConstants.VISIBILITY , rs.getString(MergeFileConstants.VISIBILITY));
				map.put(MergeFileConstants.MANUFACTURER , rs.getString(MergeFileConstants.MANUFACTURER));
				map.put(MergeFileConstants.COLOR , rs.getString(MergeFileConstants.COLOR));
				map.put(MergeFileConstants.NEWS_FROM_DATE , rs.getString(MergeFileConstants.NEWS_FROM_DATE));
				map.put(MergeFileConstants.NEWS_TO_DATE  , rs.getString(MergeFileConstants.NEWS_TO_DATE));
				map.put(MergeFileConstants.COUNTRY_OF_MANUFACTURE , rs.getString(MergeFileConstants.COUNTRY_OF_MANUFACTURE));
				map.put(MergeFileConstants.PRICE , rs.getString(MergeFileConstants.PRICE));
				map.put(MergeFileConstants.GROUP_PRICE , rs.getString(MergeFileConstants.GROUP_PRICE));
				map.put(MergeFileConstants.MSRP , rs.getString(MergeFileConstants.MSRP));
				map.put(MergeFileConstants.TIER_PRICE , rs.getString(MergeFileConstants.TIER_PRICE));
				map.put(MergeFileConstants.COST , rs.getString(MergeFileConstants.COST));
				map.put(MergeFileConstants.MIN_PRICE , rs.getString(MergeFileConstants.MIN_PRICE));
				map.put(MergeFileConstants.DIMENSION , rs.getString(MergeFileConstants.DIMENSION));
				map.put(MergeFileConstants.BY_ORDER , rs.getString(MergeFileConstants.BY_ORDER));
				map.put(MergeFileConstants.PRICE_BARGAIN , rs.getString(MergeFileConstants.PRICE_BARGAIN));
				map.put(MergeFileConstants.SPECIAL_PRICE , rs.getString(MergeFileConstants.SPECIAL_PRICE));
				map.put(MergeFileConstants.SPECIAL_FROM_DATE , rs.getString(MergeFileConstants.SPECIAL_FROM_DATE));
				map.put(MergeFileConstants.SPECIAL_TO_DATE , rs.getString(MergeFileConstants.SPECIAL_TO_DATE));
				map.put(MergeFileConstants.ENABLE_GOOGLECHECKOUT , rs.getString(MergeFileConstants.ENABLE_GOOGLECHECKOUT));
				map.put(MergeFileConstants.MSRP_ENABLED , rs.getString(MergeFileConstants.MSRP_ENABLED));
				map.put(MergeFileConstants.META_TITLE , rs.getString(MergeFileConstants.META_TITLE));
				map.put(MergeFileConstants.META_KEYWORD , rs.getString(MergeFileConstants.META_KEYWORD));
				map.put(MergeFileConstants.META_DESCRIPTION , rs.getString(MergeFileConstants.META_DESCRIPTION));
				map.put(MergeFileConstants.MEDIA_IMAGE , rs.getString(MergeFileConstants.MEDIA_IMAGE));
				map.put(MergeFileConstants.CUSTOM_DESIGN , rs.getString(MergeFileConstants.CUSTOM_DESIGN));
				map.put(MergeFileConstants.CUSTOM_DESIGN_FROM , rs.getString(MergeFileConstants.CUSTOM_DESIGN_FROM));
				map.put(MergeFileConstants.CUSTOM_DESIGN_TO , rs.getString(MergeFileConstants.CUSTOM_DESIGN_TO));
				map.put(MergeFileConstants.CUSTOM_LAYOUT_UPDATE , rs.getString(MergeFileConstants.CUSTOM_LAYOUT_UPDATE));
				map.put(MergeFileConstants.PAGE_LAYOUT , rs.getString(MergeFileConstants.PAGE_LAYOUT));
				map.put(MergeFileConstants.IS_RECURRING , rs.getString(MergeFileConstants.IS_RECURRING));
				map.put(MergeFileConstants.RECURRING_PROFILE , rs.getString(MergeFileConstants.RECURRING_PROFILE));
				map.put(MergeFileConstants.GIFT_MESSAGE_AVAILABLE , rs.getString(MergeFileConstants.GIFT_MESSAGE_AVAILABLE));
				map.put(MergeFileConstants.ATTRIBUTE_SET_NAME , rs.getString(MergeFileConstants.ATTRIBUTE_SET_NAME));
				map.put(MergeFileConstants.CATEGORY_IDS , rs.getString(MergeFileConstants.CATEGORY_IDS));
				map.put(MergeFileConstants.CREATED_AT , rs.getString(MergeFileConstants.CREATED_AT));
				map.put(MergeFileConstants.UPDATED_AT , rs.getString(MergeFileConstants.UPDATED_AT));
				map.put(MergeFileConstants.RELATION , rs.getString(MergeFileConstants.RELATION));
				map.put(MergeFileConstants.CROSS_SELL , rs.getString(MergeFileConstants.CROSS_SELL));
				map.put(MergeFileConstants.UP_SELL , rs.getString(MergeFileConstants.UP_SELL));
				map.put(MergeFileConstants.BUNDLE_SHIP , rs.getString(MergeFileConstants.BUNDLE_SHIP));
				map.put(MergeFileConstants.BUNDLE_OPTIONS , rs.getString(MergeFileConstants.BUNDLE_OPTIONS));
				map.put(MergeFileConstants.BUNDLE_SELECTIONS , rs.getString(MergeFileConstants.BUNDLE_SELECTIONS));
				map.put(MergeFileConstants.SPEC_PATH , rs.getString(MergeFileConstants.SPEC_PATH));
				map.put(MergeFileConstants.IN_DEPTH , rs.getString(MergeFileConstants.IN_DEPTH));
				map.put(MergeFileConstants.BARGAIN_QTY , rs.getString(MergeFileConstants.BARGAIN_QTY));
				map.put(MergeFileConstants.WHT , rs.getString(MergeFileConstants.WHT));
				map.put(MergeFileConstants.IS_IN_STOCK , rs.getString(MergeFileConstants.IS_IN_STOCK));
				map.put(MergeFileConstants.MANAGE_STOCK , rs.getString(MergeFileConstants.MANAGE_STOCK));
				map.put(MergeFileConstants.PRODUCT_COMPANY , rs.getString(MergeFileConstants.PRODUCT_COMPANY));
				map.put(MergeFileConstants.FREE_GOODS , rs.getString(MergeFileConstants.FREE_GOODS));
				map.put(MergeFileConstants.PRO_FREE_GOODS , rs.getString(MergeFileConstants.PRO_FREE_GOODS));
				map.put(MergeFileConstants.PRODUCT_OWNER , rs.getString(MergeFileConstants.PRODUCT_OWNER));
				map.put(MergeFileConstants.BEST_PRODUCT , rs.getString(MergeFileConstants.BEST_PRODUCT));
				map.put(MergeFileConstants.BEST_RANKING , rs.getString(MergeFileConstants.BEST_RANKING));
				map.put(MergeFileConstants.NEW_PRODUCT , rs.getString(MergeFileConstants.NEW_PRODUCT));
				map.put(MergeFileConstants.NEW_RANKING , rs.getString(MergeFileConstants.NEW_RANKING));
				map.put(MergeFileConstants.SPECIAL_PRODUCT , rs.getString(MergeFileConstants.SPECIAL_PRODUCT));
				map.put(MergeFileConstants.SPECIAL_RANKING , rs.getString(MergeFileConstants.SPECIAL_RANKING));
				
				result.put(rs.getString(MergeFileConstants.SKU), map);
			}
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
		return result;
	}
	
	public void findProductSpec(Map<String,String> mapData , List<String> listArg) throws Exception{
		
		try{
			ResultSet rs =  executeBateRS(MergeFileConstants.FINDPRODUCTSPEC,listArg);
			while(rs.next()){
				mapData.put(rs.getString(MergeFileConstants.ATTRIBUTE), rs.getString(MergeFileConstants.VALUE));
			}
			
		}catch(Exception e){
			e.printStackTrace();
			throw new Exception(e);
		}
		
		
	}

}
